package com.huilian.iotbox.admin.controller;

import com.huilian.iotbox.admin.service.CommodityService;
import com.huilian.iotbox.admin.service.UserService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.controller.BaseController;
import com.huilian.iotbox.data.dto.CommodityDto;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 龙 路 飞
 * @CreateDate: 2022-01-19 16:51
 * @Description:
 */
@RestController
@RequestMapping("/api/commodity")
public class CommodityController extends BaseController {
    @Autowired
    private CommodityService commodityService;
    @Autowired
    private UserService userService;
    @PostMapping("/list")
    public ServerResponse list(@RequestBody CommodityDto commodityDto, HttpServletRequest request){
        UserInfo userInfo = userService.getLoginUserInfo(request);
        commodityDto.setUserInfo(userInfo);
        commodityDto.setPageNum(Integer.parseInt(request.getParameter("pageNum")));
        commodityDto.setPageSize(Integer.parseInt(request.getParameter("pageSize")));
        return ServerResponse.createBySuccess(commodityService.list(commodityDto));
    }
}
